<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class pro_print_excel extends MY_Controller {
	
	function __construct()
	{
		parent::__construct();

		$this->secure_session();
	}
	
	function tenant_all()
	{

		$status_tenant='Tenant';
		$tanggal=get('tanggal');
		$x=0;

		$ls_sql	= " SELECT	*
					FROM	pro_tenant
					WHERE	UPPER(status_tenant) = 'TENANT' AND
							(UPPER(no_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_toko) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(luas_tempat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(lokasi_tempat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(alamat_lengkap) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(status_anggota) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_anggota) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_id_card) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_telephone) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_handphone) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(status_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_kontrak) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(periode_awal_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(periode_akhir_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jangka_waktu) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(harga_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(keterangan) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'no_tenant' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
		
		$ls_sql2	= "	SELECT COUNT(1)
						FROM	pro_tenant
					    WHERE	UPPER(status_tenant) = 'TENANT' AND
							(UPPER(no_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_toko) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(luas_tempat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(lokasi_tempat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(alamat_lengkap) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(status_anggota) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_anggota) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_id_card) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_telephone) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_handphone) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(status_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_kontrak) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(periode_awal_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(periode_akhir_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jangka_waktu) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(harga_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(keterangan) LIKE '%".strtoupper(post('keyword'))."%')
							ORDER BY ".(post('sort')=='' ? 'no_tenant' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('Y-m-d');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Data Tenant_".$date);

		

			
		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$this->excel->getActiveSheet()->setCellValue('B8', 'No Tenant');
			$this->excel->getActiveSheet()->setCellValue('C8', 'Nama Tenant');
			$this->excel->getActiveSheet()->setCellValue('D8', 'No Toko');
			$this->excel->getActiveSheet()->setCellValue('E8', 'Luas Tempat');
			$this->excel->getActiveSheet()->setCellValue('F8', 'Lokasi Tempat');
			$this->excel->getActiveSheet()->setCellValue('G8', 'Jenis Usaha');
			$this->excel->getActiveSheet()->setCellValue('H8', 'Alamat Lengkap');
			$this->excel->getActiveSheet()->setCellValue('I8', 'Staus Anggota');
			$this->excel->getActiveSheet()->setCellValue('J8', 'No Anggota');
			$this->excel->getActiveSheet()->setCellValue('K8', 'NO.ID Card');
			$this->excel->getActiveSheet()->setCellValue('L8', 'No Telephone');
			$this->excel->getActiveSheet()->setCellValue('M8', 'No Handphone');
			$this->excel->getActiveSheet()->setCellValue('N8', 'Status Tenant');
			$this->excel->getActiveSheet()->setCellValue('O8', 'No Kontrak');
			$this->excel->getActiveSheet()->setCellValue('P8', 'Periode Awal Sewa');
			$this->excel->getActiveSheet()->setCellValue('Q8', 'Periode Akhir Sewa');
			$this->excel->getActiveSheet()->setCellValue('R8', 'Jangka Waktu');
			$this->excel->getActiveSheet()->setCellValue('S8', 'Harga Sewa');
			$this->excel->getActiveSheet()->setCellValue('T8', 'Keterangan');
			
			$this->excel->getActiveSheet()->getStyle('B8:T8')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('B8:T8')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'B2B2B2')));
			$this->excel->getActiveSheet()->getStyle('B8:T8')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$x = 8;

			for($i=0;$i<=$data_p['total']-1;$i++){
				$x++;

				$rows = $data_p['rows'];
				$rows2 = $rows[$i];

				$this->excel->getActiveSheet()->setCellValue('B'.$x, $rows2['no_tenant']);
				$this->excel->getActiveSheet()->setCellValue('C'.$x, $rows2['nama_tenant']);
				$this->excel->getActiveSheet()->setCellValue('D'.$x, $rows2['no_toko']);
				$this->excel->getActiveSheet()->setCellValue('E'.$x, $rows2['luas_tempat']);
				$this->excel->getActiveSheet()->setCellValue('F'.$x, $rows2['lokasi_tempat']);
				$this->excel->getActiveSheet()->setCellValue('G'.$x, $rows2['jenis_usaha']);
				$this->excel->getActiveSheet()->setCellValue('H'.$x, $rows2['alamat_lengkap']);
				$this->excel->getActiveSheet()->setCellValue('I'.$x, $rows2['status_anggota']);
				$this->excel->getActiveSheet()->setCellValue('J'.$x, $rows2['no_anggota']);
				$this->excel->getActiveSheet()->setCellValue('K'.$x, $rows2['no_id_card']);
				$this->excel->getActiveSheet()->setCellValue('L'.$x, $rows2['no_telephone']);
				$this->excel->getActiveSheet()->setCellValue('M'.$x, $rows2['no_handphone']);
				$this->excel->getActiveSheet()->setCellValue('N'.$x, $rows2['status_tenant']);
				$this->excel->getActiveSheet()->setCellValue('O'.$x, $rows2['no_kontrak']);
				$this->excel->getActiveSheet()->setCellValue('P'.$x, $rows2['periode_awal_sewa']);
				$this->excel->getActiveSheet()->setCellValue('Q'.$x, $rows2['periode_akhir_sewa']);
				$this->excel->getActiveSheet()->setCellValue('R'.$x, $rows2['jangka_waktu']);
				$this->excel->getActiveSheet()->setCellValue('S'.$x, $rows2['harga_sewa']);
				$this->excel->getActiveSheet()->setCellValue('T'.$x, $rows2['keterangan']);

				$this->excel->getActiveSheet()->setCellValue('B4', strtoupper("Data Tenant"));
				$this->excel->getActiveSheet()->setCellValue('B5', $date);	

			}
		}

		$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('B8:T'.$x)->applyFromArray($styleArray);
		unset($styleArray);

		$styleArray1 = array(
		    'font'  => array(
		    'bold'  => true,
		    'uppercase' => true,
		    'size'  => 11,
		    'name'  => 'Calibri'
		    )
		);

		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(22);	
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(30);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(30);
		$this->excel->getActiveSheet()->getColumnDimension('J')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('K')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('L')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('M')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('N')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('O')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('P')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('Q')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('R')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('S')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('T')->setWidth(22);

	/*	$this->excel->getActiveSheet()->getStyle('D1:E'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('E1:E'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);*/

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Data Tenant_'.$date.'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
		header('Content-Type: text/html; charset=utf-8');
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}

	function calon_penyewa_all()
	{

		$status_tenant='Tenant';
		$tanggal=get('tanggal');
		$x=0;

		$ls_sql	= " SELECT	*
					FROM	pro_tenant
					WHERE	UPPER(status_tenant) = 'CALON PENYEWA' AND
							(UPPER(no_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_toko) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(luas_tempat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(lokasi_tempat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(alamat_lengkap) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(status_anggota) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_anggota) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_id_card) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_telephone) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_handphone) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(status_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_kontrak) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(periode_awal_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(periode_akhir_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jangka_waktu) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(harga_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(keterangan) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'no_tenant' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
		
		$ls_sql2	= "	SELECT COUNT(1)
						FROM	pro_tenant
					    WHERE	UPPER(status_tenant) = 'CALON PENYEWA' AND
							(UPPER(no_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_toko) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(luas_tempat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(lokasi_tempat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(alamat_lengkap) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(status_anggota) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_anggota) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_id_card) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_telephone) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_handphone) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(status_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_kontrak) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(periode_awal_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(periode_akhir_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jangka_waktu) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(harga_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(keterangan) LIKE '%".strtoupper(post('keyword'))."%')
							ORDER BY ".(post('sort')=='' ? 'no_tenant' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('Y-m-d');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Data Calon Penyewa_".$date);

		

			
		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$this->excel->getActiveSheet()->setCellValue('B8', 'No Tenant');
			$this->excel->getActiveSheet()->setCellValue('C8', 'Nama Tenant');
			$this->excel->getActiveSheet()->setCellValue('D8', 'No Toko');
			$this->excel->getActiveSheet()->setCellValue('E8', 'Luas Tempat');
			$this->excel->getActiveSheet()->setCellValue('F8', 'Lokasi Tempat');
			$this->excel->getActiveSheet()->setCellValue('G8', 'Jenis Usaha');
			$this->excel->getActiveSheet()->setCellValue('H8', 'Alamat Lengkap');
			$this->excel->getActiveSheet()->setCellValue('I8', 'Staus Anggota');
			$this->excel->getActiveSheet()->setCellValue('J8', 'No Telephone');
			$this->excel->getActiveSheet()->setCellValue('K8', 'No Handphone');
			$this->excel->getActiveSheet()->setCellValue('L8', 'Status Tenant');
			
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'B2B2B2')));
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$x = 8;

			for($i=0;$i<=$data_p['total']-1;$i++){
				$x++;

				$rows = $data_p['rows'];
				$rows2 = $rows[$i];

				$this->excel->getActiveSheet()->setCellValue('B'.$x, $rows2['no_tenant']);
				$this->excel->getActiveSheet()->setCellValue('C'.$x, $rows2['nama_tenant']);
				$this->excel->getActiveSheet()->setCellValue('D'.$x, $rows2['no_toko']);
				$this->excel->getActiveSheet()->setCellValue('E'.$x, $rows2['luas_tempat']);
				$this->excel->getActiveSheet()->setCellValue('F'.$x, $rows2['lokasi_tempat']);
				$this->excel->getActiveSheet()->setCellValue('G'.$x, $rows2['jenis_usaha']);
				$this->excel->getActiveSheet()->setCellValue('H'.$x, $rows2['alamat_lengkap']);
				$this->excel->getActiveSheet()->setCellValue('I'.$x, $rows2['status_anggota']);
				$this->excel->getActiveSheet()->setCellValue('J'.$x, $rows2['no_telephone']);
				$this->excel->getActiveSheet()->setCellValue('K'.$x, $rows2['no_handphone']);
				$this->excel->getActiveSheet()->setCellValue('L'.$x, $rows2['status_tenant']);

				$this->excel->getActiveSheet()->setCellValue('B4', strtoupper("Data Calon Penyewa "));
				$this->excel->getActiveSheet()->setCellValue('B5', $date);	

			}
		}

		$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('B8:L'.$x)->applyFromArray($styleArray);
		unset($styleArray);

		$styleArray1 = array(
		    'font'  => array(
		    'bold'  => true,
		    'uppercase' => true,
		    'size'  => 11,
		    'name'  => 'Calibri'
		    )
		);

		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(22);	
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(30);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('J')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('K')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('L')->setWidth(22);

	/*	$this->excel->getActiveSheet()->getStyle('D1:E'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('E1:E'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);*/

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Data Calon Penyewa_'.$date.'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}

	function tagihan_sewa_all()
	{

		$status_tenant='Tenant';
		$tanggal=get('tanggal');
		$x=0;

		$ls_sql	= " SELECT  a.no_tagihan_sewa,a.tanggal_pembayaran,a.nama_tenant,a.no_toko,a.jenis_usaha,b.periode_awal_sewa,b.periode_akhir_sewa,
							a.tanggal_pembayaran,b.jangka_waktu,b.status_tenant,a.lokasi_tempat,c.harga_sewa,c.luas_tempat,a.status_bayar,a.keterangan 
					FROM	pro_tagihan_sewa a
			        INNER JOIN pro_tenant b ON a.no_toko = b.no_toko 
			        INNER JOIN pro_sewa_gedung c ON a.no_toko = c.no_toko 
							WHERE a.tanggal_pembayaran = '$tanggal'";
		
		$ls_sql2	= "	SELECT COUNT(1)
					    FROM	pro_tagihan_sewa a
	                   	INNER JOIN pro_tenant b ON a.no_toko = b.no_toko 	
	                   	INNER JOIN pro_sewa_gedung c ON a.no_toko = c.no_toko 
						WHERE a.tanggal_pembayaran = '$tanggal' ";
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('Y-m-d');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Laporan Tagihan Sewa_".$date);

		

			
		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$this->excel->getActiveSheet()->setCellValue('B8', 'No Tagihan Sewa');
			$this->excel->getActiveSheet()->setCellValue('C8', 'Nama Tenant');
			$this->excel->getActiveSheet()->setCellValue('D8', 'No Toko');
			$this->excel->getActiveSheet()->setCellValue('E8', 'Jenis Usaha');
			$this->excel->getActiveSheet()->setCellValue('F8', 'Periode Sewa');
			$this->excel->getActiveSheet()->mergeCells('F8:G8');
			$this->excel->getActiveSheet()->setCellValue('H8', 'Luas M2');
			$this->excel->getActiveSheet()->setCellValue('I8', 'Harga Sewa');
			$this->excel->getActiveSheet()->setCellValue('J8', 'Staus Bayar');
			$this->excel->getActiveSheet()->setCellValue('K8', 'Keterangan');
			
			$this->excel->getActiveSheet()->getStyle('B8:K8')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('B8:K8')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'B2B2B2')));
			$this->excel->getActiveSheet()->getStyle('B8:K8')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$x = 8;

			for($i=0;$i<=$data_p['total']-1;$i++){
				$x++;

				$rows = $data_p['rows'];
				$rows2 = $rows[$i];

				$this->excel->getActiveSheet()->setCellValue('B'.$x, $rows2['no_tagihan_sewa']);
				$this->excel->getActiveSheet()->setCellValue('C'.$x, $rows2['nama_tenant']);
				$this->excel->getActiveSheet()->setCellValue('D'.$x, $rows2['no_toko']);
				$this->excel->getActiveSheet()->setCellValue('E'.$x, $rows2['jenis_usaha']);
				$this->excel->getActiveSheet()->setCellValue('F'.$x, $rows2['periode_awal_sewa']);
				$this->excel->getActiveSheet()->setCellValue('G'.$x, $rows2['periode_akhir_sewa']);
				$this->excel->getActiveSheet()->setCellValue('H'.$x, $rows2['luas_tempat']);
				$this->excel->getActiveSheet()->setCellValue('I'.$x, $rows2['harga_sewa']);
				$this->excel->getActiveSheet()->setCellValue('J'.$x, $rows2['status_bayar']);
				$this->excel->getActiveSheet()->setCellValue('K'.$x, $rows2['keterangan']);

				$this->excel->getActiveSheet()->setCellValue('B4', strtoupper("Laporan Tagihan Sewa"));
				$this->excel->getActiveSheet()->setCellValue('B5', $rows2['tanggal_pembayaran']);	

			}
		}

		$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('B8:K'.$x)->applyFromArray($styleArray);
		unset($styleArray);

		$styleArray1 = array(
		    'font'  => array(
		    'bold'  => true,
		    'uppercase' => true,
		    'size'  => 11,
		    'name'  => 'Calibri'
		    )
		);

		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(22);	
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('J')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('K')->setWidth(22);

	/*	$this->excel->getActiveSheet()->getStyle('D1:E'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('E1:E'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);*/

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Laporan Tagihan Sewa_'.$rows2['tanggal_pembayaran'] .'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}

	function tagihan_sewa_satuan()
	{
		$id_tagihan=get('no_tagihan_sewa');
		$x=0;

		$ls_sql	= " SELECT	*
					FROM	pro_tagihan_sewa
					WHERE	UPPER(no_tagihan_sewa)='$id_tagihan' AND
							(UPPER(no_tagihan_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_toko) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(lokasi_tempat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(harga_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(tanggal_pembayaran) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(status_bayar) LIKE '%".strtoupper(post('keyword'))."%')
							ORDER BY ".(post('sort')=='' ? 'no_tagihan_sewa' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
	
		$ls_sql2	= "	SELECT 	COUNT(1)
					    FROM 	pro_tagihan_sewa
						WHERE	(UPPER(no_tagihan_sewa) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(no_toko) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(lokasi_tempat) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(harga_sewa) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(tanggal_pembayaran) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(status_bayar) LIKE '%".strtoupper(post('keyword'))."%')
								ORDER BY ".(post('sort')=='' ? 'no_tagihan_sewa' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('d M Y');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Laporan Tagihan Sewa");

		$no = 1;

		/*$objDrawing = new PHPExcel_Worksheet_Drawing();
			$objDrawing->setName('Logo');
			$objDrawing->setDescription('Logo');
			$objDrawing->setPath('http://localhost/primkokas-new/files/logo_report.png');
			$objDrawing->setCoordinates('B1');
			$objDrawing->setHeight(36);*/
			
			/*$objPHPExcel = new PHPExcel();
			$sheet = $objPHPExcel->setSheetIndexAndTitle(1, "YOUR_SHEET_TITLE"); // first sheet
			$objDrawing = new PHPExcel_Worksheet_Drawing();
			$objDrawing->setName('Logo');
			$objDrawing->setDescription('Logo');
			$logo = base_path() . '/images/logo.png'; // Provide path to your logo file
			$objDrawing->setPath($logo);
			$objDrawing->setOffsetX(8);    // setOffsetX works properly
			$objDrawing->setOffsetY(300);  //setOffsetY has no effect
			$objDrawing->setCoordinates('B1');
			$objDrawing->setHeight(75); // logo height
			$objDrawing->setWorksheet($sheet);*/ 

		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$styleArrayUnderline = array(
			 'font' => array(
			 'underline' => PHPExcel_Style_Font::UNDERLINE_SINGLE,
			 'name' => 'Calibri',
			 'size' => 11,
			 'bold' => true
			 )
			);

			$styleArrayDefault = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 11,
			 )
			);

			$styleArrayItalic = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 11,
			 'italic' => true
			 )
			);

			$styleArrayFont = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 9,
			 'color' => array('rgb' => 'FF4719'),
			 )
			);

			$styleArrayFont1 = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 9,
			 'color' => array('rgb' => '1919FF'),
			 )
			);

			$rows = $data_p['rows'];
			$rows2 = $rows[0];


			$this->excel->getActiveSheet()->setCellValue('K1', 'PRIMER KOPERASI KARYAWAN KRAKATAU STEEL');
			$this->excel->getActiveSheet()->getStyle('K1')->applyFromArray($styleArrayFont);
			$this->excel->getActiveSheet()->getStyle('K1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);

			$this->excel->getActiveSheet()->setCellValue('K2', 'Gedung Krakatau Junction Lt. 3, Jl. KH. Yasin Neji Komp. PT KS');
			$this->excel->getActiveSheet()->setCellValue('K3', 'Cilegon - Banten 42435');
			$this->excel->getActiveSheet()->setCellValue('K4', 'Phone +62 (254) 392784, 372289 Fax. + (254) 372290, 398884');
			$this->excel->getActiveSheet()->setCellValue('K5', 'Website : www.primkokas.co.id');
			$this->excel->getActiveSheet()->setCellValue('K6', 'email: info@primkokas.co.id');
			$this->excel->getActiveSheet()->getStyle('K2:K6')->applyFromArray($styleArrayFont1);
			$this->excel->getActiveSheet()->getStyle('K2:K6')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);

			$this->excel->getActiveSheet()->setCellValue('A8', 'Nomor');
			$this->excel->getActiveSheet()->setCellValue('A9', 'Lampiran');
			$this->excel->getActiveSheet()->setCellValue('A10', 'Perihal');
			$this->excel->getActiveSheet()->getStyle('A10')->getFont()->setBold(true);

			$this->excel->getActiveSheet()->setCellValue('B8', ':' );
			$this->excel->getActiveSheet()->setCellValue('C8', $rows2['no_tagihan_sewa']);
			$this->excel->getActiveSheet()->setCellValue('C9', '1 (satu) set.');
			$this->excel->getActiveSheet()->setCellValue('C10', 'Konfirmasi Tagihan');

			$this->excel->getActiveSheet()->getStyle('C10')->applyFromArray($styleArrayUnderline);
			$this->excel->getActiveSheet()->setCellValue('C12', 'Kepada Yth.');
			$this->excel->getActiveSheet()->setCellValue('C13', 'Bapak/Ibu '.$rows2['nama_tenant']);
			$this->excel->getActiveSheet()->getStyle('C13')->getFont()->setBold(true);

			$this->excel->getActiveSheet()->setCellValue('C14',  $rows2['lokasi_tempat'].'No. '.$rows2['no_toko']);
			$this->excel->getActiveSheet()->setCellValue('C15', 'Di');
			$this->excel->getActiveSheet()->setCellValue('D16', 'Tempat');
			$this->excel->getActiveSheet()->setCellValue('C18', 'Dengan Hormat');

			$this->excel->getActiveSheet()->setCellValue('C20', 'Puji syukur ke hadirat Allah SWT teriring doa semoga Bapak/Ibu dalam keadaan ');
			$this->excel->getActiveSheet()->setCellValue('C21', 'sehat wal afiat dan senantiasa mendapat lindungan-Nya di dalam menjalankan tugas sehari-hari. Amin.');
			$this->excel->getActiveSheet()->setCellValue('C22', 'tugas sehari-hari. Amin.');

			$this->excel->getActiveSheet()->setCellValue('C24', 'Bersama ini kami selaku Pihak Property Management ingin menyampaikan');
			$this->excel->getActiveSheet()->setCellValue('C25', 'informasi bahwa Bapak/Ibu ' .$rows2['nama_tenant']. ' belum menyelesaikan tagihan sewa toko ' .$rows2['no_toko']. ' untuk');
			$this->excel->getActiveSheet()->setCellValue('C26', 'periode ' .$rows2['tanggal_pembayaran']. ' yaitu sebagai berikut:');

			$this->excel->getActiveSheet()->setCellValue('C28', '1.');
			$this->excel->getActiveSheet()->setCellValue('D28', 'Tagihan Sewa');
			$this->excel->getActiveSheet()->getStyle('C28:D28')->getFont()->setBold(true);

			$this->excel->getActiveSheet()->setCellValue('C29', '-');
			$this->excel->getActiveSheet()->setCellValue('D29', 'Periode' .$rows2['tanggal_pembayaran']);
			$this->excel->getActiveSheet()->setCellValue('G29', '@ Rp.');
			$this->excel->getActiveSheet()->setCellValue('H29',  $rows2['harga_sewa']);
			$this->excel->getActiveSheet()->setCellValue('C31', 'Total Keseluruhan yang harus di bayar');

			$this->excel->getActiveSheet()->setCellValue('G31', '@ Rp.');
			$this->excel->getActiveSheet()->setCellValue('H31', $rows2['harga_sewa']);
			$this->excel->getActiveSheet()->getStyle('C31:G31')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->setCellValue('C32', $this->terbilang($rows2['harga_sewa']));
			$this->excel->getActiveSheet()->getStyle('C32')->applyFromArray($styleArrayItalic);
			$this->excel->getActiveSheet()->getStyle('H29')->getNumberFormat()->setFormatCode('#,##0'); 
			$this->excel->getActiveSheet()->getStyle('H31')->getNumberFormat()->setFormatCode('#,##0'); 

			$this->excel->getActiveSheet()->setCellValue('C34', 'Kami harapkan Bapak/Ibu dapat segera menyelesaikan tagihan tersebut sesuai ');
			$this->excel->getActiveSheet()->setCellValue('C35', 'syarat dan ketentuan yang berlaku.');
			$this->excel->getActiveSheet()->setCellValue('C36', 'Demikian pemberitahuan ini kami sampaikan, atas perhatian dan kerjasamanya');
			$this->excel->getActiveSheet()->setCellValue('C37', 'diucapkan terima kasih.');

			$this->excel->getActiveSheet()->setCellValue('E40', 'Mengetahui,');
			$this->excel->getActiveSheet()->setCellValue('E45', 'Aan Supriana');
			$this->excel->getActiveSheet()->setCellValue('E46', 'Internal Busines & Property Div. Manager');

			$this->excel->getActiveSheet()->setCellValue('I39', 'Cilegon, '.$date);
			$this->excel->getActiveSheet()->setCellValue('I40', 'PRIMER KOPERASI KARYAWAN');
			$this->excel->getActiveSheet()->setCellValue('I41', 'KRAKATAU STEEL');
			$this->excel->getActiveSheet()->getStyle('I40:I41')->getFont()->setBold(true);

			$this->excel->getActiveSheet()->setCellValue('I45', 'Ngajito');
			$this->excel->getActiveSheet()->setCellValue('I46', 'Property Div.');

			$this->excel->getActiveSheet()->setCellValue('C48', 'Tembusan :');
			$this->excel->getActiveSheet()->setCellValue('D49', '1. Yth. Ketua Umun PRIMKOKAS');
			$this->excel->getActiveSheet()->setCellValue('D50', '2. Arsip');

			$this->excel->getActiveSheet()->getStyle('E45:I45')->applyFromArray($styleArrayUnderline);
			$this->excel->getActiveSheet()->getStyle('E39:I46')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

		}

		$this->excel->getActiveSheet()->getColumnDimension('A')->setWidth(8.4);
		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(0.7);
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(0.7);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(8.5);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(15.5);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(9.4);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(12);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(1);

/*
		$this->excel->getActiveSheet()->getStyle('D1:C'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('G1:G'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);*/

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		//$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Laporan Tagihan Sewa_'.$rows2['no_tagihan_sewa'].'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}


	 

	function permintaan()
	{
		$no_surat=get('no_surat');
		$x=0;

		$ls_sql	=  "SELECT
					a.ID_PERMINTAAN_PERANGKAT,
					a.TANGGAL,
					a.NAMA,
					b.NAMA_DEPARTEMEN as DEPARTEMEN,
					a.PERMOHONAN_MASALAH,
					concat('- ',REPLACE(a.PILIHAN_PERMINTAAN, ',', '<br>- ')) as PILIHAN_PERMINTAAN
					FROM	PRO_DATA_PERMINTAAN_PERANGKAT a
					left join HRD_DEPARTEMEN b
					on a.DEPARTEMEN = b.ID_DEPARTEMEN_PK
					WHERE	(UPPER(a.ID_PERMINTAAN_PERANGKAT) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.TANGGAL) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.NAMA) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(b.NAMA_DEPARTEMEN) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.PERMOHONAN_MASALAH) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.PILIHAN_PERMINTAAN) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'a.ID_PERMINTAAN_PERANGKAT' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	

		$ls_sql2	= "	SELECT 	COUNT(1)
						FROM	PRO_DATA_PERMINTAAN_PERANGKAT a
						left join HRD_DEPARTEMEN b
						on a.DEPARTEMEN = b.ID_DEPARTEMEN_PK
						WHERE	(UPPER(a.ID_PERMINTAAN_PERANGKAT) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.TANGGAL) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.NAMA) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(b.NAMA_DEPARTEMEN) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.PERMOHONAN_MASALAH) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.PILIHAN_PERMINTAAN) LIKE '%".strtoupper(post('keyword'))."%')
						ORDER BY ".(post('sort')=='' ? 'a.ID_PERMINTAAN_PERANGKAT' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$ls_sql3 = "	SELECT
							ROWNUM as no,
							a.ID_PENAMBAHAN_PERANGKAT_DTL,
							a.ID_PENAMBAHAN_PERANGKAT,
							a.ID_BARANG,
							b.NAMA_BARANG,
							a.JUMLAH,
							a.LOKASI,
							a.KETERANGAN
							FROM
							PRO_DATA_PENAMBAHAN_PRK_DTL a
							left join PRO_SETUP_STOCK b
							on a.ID_BARANG = b.KODE_BARANG
							WHERE a.ID_PENAMBAHAN_PERANGKAT = $id
							and	(UPPER(b.NAMA_BARANG) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.LOKASI) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.KETERANGAN) LIKE '%".strtoupper(post('keyword'))."%')
							ORDER BY ".(post('sort')=='' ? 'a.ID_PENAMBAHAN_PERANGKAT' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	

		$ls_sql4 = "	SELECT COUNT(1)
							FROM
							PRO_DATA_PENAMBAHAN_PRK_DTL a
							left join PRO_SETUP_STOCK b
							on a.ID_BARANG = b.KODE_BARANG
							WHERE a.ID_PENAMBAHAN_PERANGKAT = $id
							and	(UPPER(b.NAMA_BARANG) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.LOKASI) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.KETERANGAN) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'a.ID_PENAMBAHAN_PERANGKAT' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	

		$total1 = $this->get_data($ls_sql4);

		$result1 = $this->db->query($ls_sql3);

		$data_p1 = array(	'rowsd'=> $result1->result_array(), 
								'totald' => $total1);

		$date = date('d M Y');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Laporan Tagihan Listrik");

		$no = 1;

		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$styleArrayUnderline = array(
			 'font' => array(
			 'underline' => PHPExcel_Style_Font::UNDERLINE_SINGLE,
			 'name' => 'Calibri',
			 'size' => 11,
			 'bold' => true
			 )
			);

			$styleArrayDefault = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 11,
			 )
			);

			$styleArrayItalic = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 11,
			 'italic' => true
			 )
			);

			$styleArrayFont = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 15,
			 'bold' => true,
			 'italic' => true
			 )
			);

			$styleArrayFont1 = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 12,
			 'bold' => true,
			 'italic' => true
			 )
			);

			$rows = $data_p['rows'];
			$rows2 = $rows[0];



			$this->excel->getActiveSheet()->setCellValue('D4', strtoupper('FORM TECHNICAL SUPPORT'));
			$this->excel->getActiveSheet()->getStyle('D4')->applyFromArray($styleArrayFont);
			$this->excel->getActiveSheet()->setCellValue('D5', 'Building Managament & Mtc Dept.');
			$this->excel->getActiveSheet()->getStyle('D5')->applyFromArray($styleArrayFont1);
			
			$this->excel->getActiveSheet()->setCellValue('B7', 'ID Permintaan Perangkat');
			$this->excel->getActiveSheet()->setCellValue('B8', 'Tanggal');
			$this->excel->getActiveSheet()->setCellValue('B9', 'Departement');

			$this->excel->getActiveSheet()->setCellValue('B11', 'Pilih Permintaan Anda');
			$this->excel->getActiveSheet()->setCellValue('C12', 'Perbaikan');
			$this->excel->getActiveSheet()->setCellValue('C13', 'Pembelian/Pengadaan Baru');
			$this->excel->getActiveSheet()->setCellValue('C14', 'Penggantian Baru');
			$this->excel->getActiveSheet()->getStyle('C9')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->setCellValue('A10', 'Nama Penyelenggara ');
			$this->excel->getActiveSheet()->setCellValue('C10', ':');
			$this->excel->getActiveSheet()->setCellValue('D10', $rows2['nama_penyelenggara']);
			$this->excel->getActiveSheet()->setCellValue('A11', 'Alamat ');
			$this->excel->getActiveSheet()->setCellValue('C11', ':');
			$this->excel->getActiveSheet()->setCellValue('D11', $rows2['alamat']);
			$this->excel->getActiveSheet()->setCellValue('A12', 'Diwakili Oleh');
			$this->excel->getActiveSheet()->setCellValue('C12', ':');
			$this->excel->getActiveSheet()->setCellValue('D12', $rows2['diwakili_oleh']);

			$this->excel->getActiveSheet()->setCellValue('A14',  'Adapun keterangan kegiatan adalah sebagai berikut :');

			$this->excel->getActiveSheet()->getStyle('B4:E3')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_LEFT);	
			$this->excel->getActiveSheet()->getStyle('B4:E3')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);

			$this->excel->getActiveSheet()->setCellValue('A16', 'Nama Kegiatan');
			$this->excel->getActiveSheet()->setCellValue('C16', ':');
			$this->excel->getActiveSheet()->setCellValue('D16', $rows2['nama_kegiatan']);
			$this->excel->getActiveSheet()->setCellValue('A17', 'Keterangan Kegiatan');
			$this->excel->getActiveSheet()->setCellValue('C17', ':');
			$this->excel->getActiveSheet()->setCellValue('D17', $rows2['catatan_kegiatan']);
			$this->excel->getActiveSheet()->getStyle('A17:D17')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);	
			$this->excel->getActiveSheet()->getStyle('A17:D17')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$this->excel->getActiveSheet()->mergeCells('D17:F17');
			$this->excel->getActiveSheet()->getStyle('D17:F17')->getAlignment()->setWrapText(true);

			$this->excel->getActiveSheet()->setCellValue('A18', 'Hari/Tanggal Kegiatan');
			$this->excel->getActiveSheet()->setCellValue('C18', ':');
			$this->excel->getActiveSheet()->setCellValue('D18', $rows2['tanggal_mulai_kegiatan'].' S/D '.$rows2['tanggal_selesai_kegiatan']);
			$this->excel->getActiveSheet()->setCellValue('A19', 'Pukul');
			$this->excel->getActiveSheet()->setCellValue('C19', ':');
			$this->excel->getActiveSheet()->setCellValue('D19', $rows2['pukul']);
			$this->excel->getActiveSheet()->setCellValue('A20', 'Tempat Kegiatan');
			$this->excel->getActiveSheet()->setCellValue('C20', ':');
			$this->excel->getActiveSheet()->setCellValue('D20', $rows2['tempat_kegiatan']);

			$this->excel->getActiveSheet()->setCellValue('A22', 'Dengan Catatan Sebagai Berikut :');
			$this->excel->getActiveSheet()->setCellValue('A23', '1. Menjaga norma-norma kesopanan.');
			$this->excel->getActiveSheet()->setCellValue('A24', '2. Tidak mengganggu kenyamanan Krakatau Junction.');
			$this->excel->getActiveSheet()->setCellValue('A25', '3. Menjaga keamanan, ketertiban dan kebersihan selama kegiatan berlangsung.');
			$this->excel->getActiveSheet()->setCellValue('A26', '4. Tidak diperkenankan membawa senjata tajam, minuman beralkohol dan benda');
			$this->excel->getActiveSheet()->setCellValue('A27', '     lainnya yang melanggar hukum di area Krakatau Junction');
			$this->excel->getActiveSheet()->setCellValue('A28', '5. Apabila terjadi pelanggaran, maka pihak keamanan Krakatau Junction berhak untuk');
			$this->excel->getActiveSheet()->setCellValue('A29', '     meberhentikan kegiatan tersebut.');

			$this->excel->getActiveSheet()->setCellValue('A31', 'Demikian surat keterangan ini kami buat untuk dapat di pergunakan sebagaimana');
			$this->excel->getActiveSheet()->setCellValue('A32', 'mestinya.');

			$this->excel->getActiveSheet()->setCellValue('G34', 'Cilegon, '.$date);
			$this->excel->getActiveSheet()->setCellValue('G35', 'PRIMER KOPRASI KARYAWAN');
			$this->excel->getActiveSheet()->setCellValue('G36', 'KRAKATAU STEEL');


			$this->excel->getActiveSheet()->setCellValue('G41', 'Ngajito');
			$this->excel->getActiveSheet()->setCellValue('G42', 'Total Keseluruhan yang harus di bayar');
			$this->excel->getActiveSheet()->getStyle('G35:G41')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);	
			$this->excel->getActiveSheet()->getStyle('G35:G41')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$this->excel->getActiveSheet()->getStyle('G34:G42')->applyFromArray($styleArrayUnderline);

			$this->excel->getActiveSheet()->setCellValue('B42', 'Cc. Arsip');
			
			// $this->excel->getActiveSheet()->getStyle('E45:I45')->applyFromArray($styleArrayUnderline);
			// $this->excel->getActiveSheet()->getStyle('E39:I46')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

		}

		$this->excel->getActiveSheet()->getColumnDimension('A')->setWidth(8.8);
		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(10.67);
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(0.83);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(15.41);
		$this->excel->getActiveSheet()->getRowDimension('17')->setRowHeight(80);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(8.43);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(8.43);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(10.86);

/*
		$this->excel->getActiveSheet()->getStyle('D1:C'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('G1:G'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);*/

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		//$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Data Penyelenggara_'.$rows2['no_surat'].'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}

	function data_penyelenggara_satuan2()
	{
		$no_surat=get('no_surat');
		$x=0;

		$ls_sql	= " SELECT	*
					FROM	pro_surat_penyelenggara 
					WHERE	UPPER(no_surat)= '$no_surat' AND
							(UPPER(no_surat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_penyelenggara) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'no_surat' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
	
		$ls_sql2	= "	SELECT 	COUNT(1)
						FROM	pro_surat_penyelenggara 
						WHERE	(UPPER(no_surat) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(nama_penyelenggara) LIKE '%".strtoupper(post('keyword'))."%')
						ORDER BY ".(post('sort')=='' ? 'no_surat' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('d M Y');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Laporan Tagihan Listrik");

		$no = 1;

		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$styleArrayUnderline = array(
			 'font' => array(
			 'underline' => PHPExcel_Style_Font::UNDERLINE_SINGLE,
			 'name' => 'Calibri',
			 'size' => 11,
			 'bold' => true
			 )
			);

			$styleArrayDefault = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 11,
			 )
			);

			$styleArrayItalic = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 11,
			 'italic' => true
			 )
			);

			$styleArrayFont = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 9,
			 'color' => array('rgb' => 'FF4719'),
			 )
			);

			$styleArrayFont1 = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 9,
			 'color' => array('rgb' => '1919FF'),
			 )
			);

			$rows = $data_p['rows'];
			$rows2 = $rows[0];



			$this->excel->getActiveSheet()->setCellValue('E1', strtoupper('SURAT IZIN PENYELENGGARAN KEGIATAN'));
			$this->excel->getActiveSheet()->getStyle('E1')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->setCellValue('E2', 'PRIMKOKAS - KRAKATAU JUNCTION');
			$this->excel->getActiveSheet()->setCellValue('E3', $rows2['no_surat']);
			$this->excel->getActiveSheet()->getStyle('E2')->applyFromArray($styleArrayUnderline);
			$this->excel->getActiveSheet()->getStyle('E1:E3')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);	
			$this->excel->getActiveSheet()->getStyle('E1:E3')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$this->excel->getActiveSheet()->setCellValue('A5', 'Puji syukur kehadirat Allah SWT, teriring doa semoga Bapak/Ibu dalam keaadan');
			$this->excel->getActiveSheet()->setCellValue('A6', 'sehat wal afiat dan senantiasa mendapat lindungan-nya di dalam menjalankan tugas');
			$this->excel->getActiveSheet()->setCellValue('A7', 'sehari-hari. Amin');

			$this->excel->getActiveSheet()->setCellValue('A9', 'Dengan ini Primkokas');
			$this->excel->getActiveSheet()->setCellValue('C9','Memberikan Izin');
			$this->excel->getActiveSheet()->setCellValue('E9', 'Kepada :');
			$this->excel->getActiveSheet()->getStyle('C9')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->setCellValue('A10', 'Nama Penyelenggara ');
			$this->excel->getActiveSheet()->setCellValue('C10', ':');
			$this->excel->getActiveSheet()->setCellValue('D10', $rows2['nama_penyelenggara']);
			$this->excel->getActiveSheet()->setCellValue('A11', 'Alamat ');
			$this->excel->getActiveSheet()->setCellValue('C11', ':');
			$this->excel->getActiveSheet()->setCellValue('D11', $rows2['alamat']);
			$this->excel->getActiveSheet()->setCellValue('A12', 'Diwakili Oleh');
			$this->excel->getActiveSheet()->setCellValue('C12', ':');
			$this->excel->getActiveSheet()->setCellValue('D12', $rows2['diwakili_oleh']);

			$this->excel->getActiveSheet()->setCellValue('A14',  'Adapun keterangan kegiatan adalah sebagai berikut :');
			
			$this->excel->getActiveSheet()->setCellValue('A16', 'Nama Kegiatan');
			$this->excel->getActiveSheet()->setCellValue('C16', ':');
			$this->excel->getActiveSheet()->setCellValue('D16', $rows2['nama_kegiatan']);
			$this->excel->getActiveSheet()->setCellValue('A17', 'Keterangan Kegiatan');
			$this->excel->getActiveSheet()->setCellValue('C17', ':');
			$this->excel->getActiveSheet()->setCellValue('D17', $rows2['catatan_kegiatan']);
			$this->excel->getActiveSheet()->getStyle('A17:D17')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);	
			$this->excel->getActiveSheet()->getStyle('A17:D17')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$this->excel->getActiveSheet()->mergeCells('D17:F17');
			$this->excel->getActiveSheet()->getStyle('D17:F17')->getAlignment()->setWrapText(true);

			$this->excel->getActiveSheet()->setCellValue('A18', 'Hari/Tanggal Kegiatan');
			$this->excel->getActiveSheet()->setCellValue('C18', ':');
			$this->excel->getActiveSheet()->setCellValue('D18', $rows2['tanggal_mulai_kegiatan'].' S/D '.$rows2['tanggal_selesai_kegiatan']);
			$this->excel->getActiveSheet()->setCellValue('A19', 'Pukul');
			$this->excel->getActiveSheet()->setCellValue('C19', ':');
			$this->excel->getActiveSheet()->setCellValue('D19', $rows2['pukul']);
			$this->excel->getActiveSheet()->setCellValue('A20', 'Tempat Kegiatan');
			$this->excel->getActiveSheet()->setCellValue('C20', ':');
			$this->excel->getActiveSheet()->setCellValue('D20', $rows2['tempat_kegiatan']);

			$this->excel->getActiveSheet()->setCellValue('A22', 'Dengan Catatan Sebagai Berikut :');
			$this->excel->getActiveSheet()->setCellValue('A23', '1. Menjaga norma-norma kesopanan.');
			$this->excel->getActiveSheet()->setCellValue('A24', '2. Tidak mengganggu kenyamanan Krakatau Junction.');
			$this->excel->getActiveSheet()->setCellValue('A25', '3. Menjaga keamanan, ketertiban dan kebersihan selama kegiatan berlangsung.');
			$this->excel->getActiveSheet()->setCellValue('A26', '4. Tidak diperkenankan membawa senjata tajam, minuman beralkohol dan benda');
			$this->excel->getActiveSheet()->setCellValue('A27', '     lainnya yang melanggar hukum di area Krakatau Junction');
			$this->excel->getActiveSheet()->setCellValue('A28', '5. Apabila terjadi pelanggaran, maka pihak keamanan Krakatau Junction berhak untuk');
			$this->excel->getActiveSheet()->setCellValue('A29', '     meberhentikan kegiatan tersebut.');

			$this->excel->getActiveSheet()->setCellValue('A31', 'Demikian surat keterangan ini kami buat untuk dapat di pergunakan sebagaimana');
			$this->excel->getActiveSheet()->setCellValue('A32', 'mestinya.');

			$this->excel->getActiveSheet()->setCellValue('G34', 'Cilegon, '.$date);
			$this->excel->getActiveSheet()->setCellValue('G35', 'PRIMER KOPRASI KARYAWAN');
			$this->excel->getActiveSheet()->setCellValue('G36', 'KRAKATAU STEEL');


			$this->excel->getActiveSheet()->setCellValue('G41', 'Ngajito');
			$this->excel->getActiveSheet()->setCellValue('G42', 'Total Keseluruhan yang harus di bayar');
			$this->excel->getActiveSheet()->getStyle('G35:G41')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);	
			$this->excel->getActiveSheet()->getStyle('G35:G41')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$this->excel->getActiveSheet()->getStyle('G34:G42')->applyFromArray($styleArrayUnderline);

			$this->excel->getActiveSheet()->setCellValue('B42', 'Cc. Arsip');
			
			// $this->excel->getActiveSheet()->getStyle('E45:I45')->applyFromArray($styleArrayUnderline);
			// $this->excel->getActiveSheet()->getStyle('E39:I46')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

		}

		$this->excel->getActiveSheet()->getColumnDimension('A')->setWidth(8.8);
		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(10.67);
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(0.83);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(15.41);
		$this->excel->getActiveSheet()->getRowDimension('17')->setRowHeight(80);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(8.43);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(8.43);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(10.86);

/*
		$this->excel->getActiveSheet()->getStyle('D1:C'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('G1:G'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);*/

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		//$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Data Penyelenggara_'.$rows2['no_surat'].'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}

	function tagihan_listrik_satuan()
	{
		$id_tagihan=get('no_tagihan_listrik');
		$x=0;

		$ls_sql	= " SELECT	*
					FROM	pro_tagihan_listrik
					WHERE	UPPER(no_tagihan_listrik)='$id_tagihan' AND
							(UPPER(no_tagihan_listrik) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_toko) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(tanggal) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(kwh_awal_meter) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(kwh_akhir_meter) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(kwh_terpakai) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(tarif_per_kwh) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jumlah_pemakaian) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(mcb) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(biaya_beban) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jumlah_biaya_beban) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(total_tagihan) LIKE '%".strtoupper(post('keyword'))."%') 
							ORDER BY ".(post('sort')=='' ? 'no_tagihan_listrik' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
	
		$ls_sql2	= "	SELECT COUNT(1)
					    FROM pro_tagihan_listrik
						WHERE	(UPPER(no_tagihan_listrik) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_toko) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(tanggal) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(kwh_awal_meter) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(kwh_akhir_meter) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(kwh_terpakai) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(tarif_per_kwh) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jumlah_pemakaian) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(mcb) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(biaya_beban) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jumlah_biaya_beban) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(total_tagihan) LIKE '%".strtoupper(post('keyword'))."%') 
							ORDER BY ".(post('sort')=='' ? 'no_tagihan_listrik' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
	
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('Y-m-d');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Laporan Tagihan Listrik");

		$no = 1;

		/*$objDrawing = new PHPExcel_Worksheet_Drawing();
			$objDrawing->setName('Logo');
			$objDrawing->setDescription('Logo');
			$objDrawing->setPath('http://localhost/primkokas-new/files/logo_report.png');
			$objDrawing->setCoordinates('B1');
			$objDrawing->setHeight(36);*/
			
			/*$objPHPExcel = new PHPExcel();
			$sheet = $objPHPExcel->setSheetIndexAndTitle(1, "YOUR_SHEET_TITLE"); // first sheet
			$objDrawing = new PHPExcel_Worksheet_Drawing();
			$objDrawing->setName('Logo');
			$objDrawing->setDescription('Logo');
			$logo = base_path() . '/images/logo.png'; // Provide path to your logo file
			$objDrawing->setPath($logo);
			$objDrawing->setOffsetX(8);    // setOffsetX works properly
			$objDrawing->setOffsetY(300);  //setOffsetY has no effect
			$objDrawing->setCoordinates('B1');
			$objDrawing->setHeight(75); // logo height
			$objDrawing->setWorksheet($sheet);*/ 

		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$styleArrayUnderline = array(
			 'font' => array(
			 'underline' => PHPExcel_Style_Font::UNDERLINE_SINGLE,
			 'name' => 'Century Gothic',
			 'size' => 11,
			 'bold' => true
			 )
			);

			$styleArrayDefault = array(
			 'font' => array(
			 'name' => 'Century Gothic',
			 'size' => 11,
			 )
			);

			$styleArrayItalic = array(
			 'font' => array(
			 'name' => 'Century Gothic',
			 'size' => 11,
			 'italic' => true
			 )
			);



			$this->excel->getActiveSheet()->setCellValue('B4', 'Tagihan Listrik Bulan');
			$this->excel->getActiveSheet()->setCellValue('B8', 'No Tagihan Listrik');
			$this->excel->getActiveSheet()->setCellValue('B9', 'No Toko');
			$this->excel->getActiveSheet()->setCellValue('B10', 'Nama Pelanggan');
			$this->excel->getActiveSheet()->setCellValue('B11', 'Jenis Usaha');
			$this->excel->getActiveSheet()->setCellValue('B13', 'Kwh Awal Meter');
			$this->excel->getActiveSheet()->setCellValue('B14', 'Kwh Akhir Meter');
			$this->excel->getActiveSheet()->setCellValue('B15', 'Kwh Terpakai');
			$this->excel->getActiveSheet()->setCellValue('B16', 'Tarif Per Kwh');
			$this->excel->getActiveSheet()->setCellValue('B17', 'Jumlah Pemakaian');
			$this->excel->getActiveSheet()->setCellValue('B19', 'MCB (A)');
			$this->excel->getActiveSheet()->setCellValue('B20', 'Biaya Beban');
			$this->excel->getActiveSheet()->setCellValue('B21', 'Jumlah Biaya Beban');
			$this->excel->getActiveSheet()->setCellValue('B23', 'Total Tagihan');
			$this->excel->getActiveSheet()->setCellValue('B24', 'Terbilang');
			$this->excel->getActiveSheet()->setCellValue('B29', 'Mengetahui');
			$this->excel->getActiveSheet()->setCellValue('B34', 'Nanang Rosdiana');
			$this->excel->getActiveSheet()->setCellValue('B35', 'Finance Div. Mgr');
			$this->excel->getActiveSheet()->setCellValue('B40', 'Pembayaran dapat dilakukan malalui transfer via rekening No. 155-00-0259247-8');
			$this->excel->getActiveSheet()->setCellValue('B41', 'a/n Property PRIMKOKAS di Bank Mandiri Cab. Cilegon – Anyer atau setor langsung');
			$this->excel->getActiveSheet()->setCellValue('B42', 'ke kasir Primkokas. Pembayaran syah setelah uang dapat dicairkan atau disetor dengan bukti  kwitansi.');

			
			$this->excel->getActiveSheet()->getStyle('B29:B35')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			//unset($styleArrayUnderline);

			$this->excel->getActiveSheet()->setCellValue('C4', ':');
			$this->excel->getActiveSheet()->setCellValue('C8', ':');
			$this->excel->getActiveSheet()->setCellValue('C9', ':');
			$this->excel->getActiveSheet()->setCellValue('C10', ':');
			$this->excel->getActiveSheet()->setCellValue('C11', ':');
			$this->excel->getActiveSheet()->setCellValue('C13', ':');
			$this->excel->getActiveSheet()->setCellValue('C14', ':');
			$this->excel->getActiveSheet()->setCellValue('C15', ':');
			$this->excel->getActiveSheet()->setCellValue('C17', ':');
			$this->excel->getActiveSheet()->setCellValue('C19', ':');
			$this->excel->getActiveSheet()->setCellValue('C20', ':');
			$this->excel->getActiveSheet()->setCellValue('C21', ':');
			$this->excel->getActiveSheet()->setCellValue('C22', ':');
			$this->excel->getActiveSheet()->setCellValue('C23', ':');
			$this->excel->getActiveSheet()->setCellValue('C24', ':');

			$this->excel->getActiveSheet()->setCellValue('E23', '(Jml Pemakaian + Jml Biaya Beban)');
			$this->excel->getActiveSheet()->setCellValue('F27', 'Cilegon'."".'('.$date.')');
			$this->excel->getActiveSheet()->setCellValue('F28', 'PRIMER KOPERASI KARYAWAN');
			$this->excel->getActiveSheet()->setCellValue('F29', 'KRAKATAU STEEL');
			$this->excel->getActiveSheet()->setCellValue('F34', 'Ngatijo');
			$this->excel->getActiveSheet()->setCellValue('F35', 'Property Div.');
			
			


			
			$this->excel->getActiveSheet()->getStyle('F27:F35')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$this->excel->getActiveSheet()->getStyle('B40:F42')->applyFromArray($styleArrayItalic);
			$this->excel->getActiveSheet()->getStyle('B35:F35')->getFont()->setBold(true);
			//$this->excel->getActiveSheet()->getStyle('B8:B17')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'EEEE11')));
			//$this->excel->getActiveSheet()->getStyle('B8:B17')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

				$rows = $data_p['rows'];
				$rows2 = $rows[0];

				$this->excel->getActiveSheet()->setCellValue('D4', $rows2['tanggal']);
				$this->excel->getActiveSheet()->setCellValue('D8', $rows2['no_tagihan_listrik']);
				$this->excel->getActiveSheet()->setCellValue('D9', $rows2['no_toko']);
				$this->excel->getActiveSheet()->setCellValue('D10', $rows2['nama_tenant']);
				$this->excel->getActiveSheet()->setCellValue('D11', $rows2['jenis_usaha']);
				$this->excel->getActiveSheet()->setCellValue('B5', $rows2['lokasi_tempat']." ".'Krakatau Juction');
				$this->excel->getActiveSheet()->setCellValue('D13', $rows2['kwh_awal_meter']);
				$this->excel->getActiveSheet()->setCellValue('D14', $rows2['kwh_akhir_meter']);
				$this->excel->getActiveSheet()->setCellValue('D15', $rows2['kwh_terpakai']);
				$this->excel->getActiveSheet()->setCellValue('D16', $rows2['tarif_per_kwh']);
				$this->excel->getActiveSheet()->setCellValue('D17', $rows2['jumlah_pemakaian']);
				$this->excel->getActiveSheet()->setCellValue('D19', $rows2['mcb']);
				$this->excel->getActiveSheet()->setCellValue('D21', $rows2['biaya_beban']);
				$this->excel->getActiveSheet()->setCellValue('D22', $rows2['jumlah_biaya_beban']);
				$this->excel->getActiveSheet()->setCellValue('D23', $rows2['total_tagihan'] );
				$this->excel->getActiveSheet()->setCellValue('D24', $this->terbilang($rows2['total_tagihan']));

				$this->excel->getActiveSheet()->getStyle('D23')->getFont()->setBold(true);
				//$this->excel->getActiveSheet()->getStyle('B34:F35')->getFont()->setBold(true);

				$this->excel->getActiveSheet()->getStyle('B4:E34')->applyFromArray($styleArrayDefault);
				//unset($styleArrayDefault);
				$this->excel->getActiveSheet()->getStyle('E23')->applyFromArray($styleArrayItalic);
				$this->excel->getActiveSheet()->getStyle('B34:F34')->applyFromArray($styleArrayUnderline);


		}

		
					

	/*	$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('B8:C'.$x)->applyFromArray($styleArray);
		unset($styleArray);*/

		/*$styleArray1 = array(
		    'font'  => array(
		    'bold'  => true,
		    'uppercase' => true,
		    'size'  => 11,
		    'name'  => 'Calibri'
		    )
		);*/
		
		$this->excel->getActiveSheet()->getColumnDimension('A')->setWidth(1.7);
		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(5.5);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(20.5);


		$this->excel->getActiveSheet()->getStyle('D1:C'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	/*$this->excel->getActiveSheet()->getStyle('G1:G'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);*/

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		//$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Laporan Tagihan Listrik_'.$rows2['no_tagihan_listrik'].'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}

	function tagihan_listrik_all()
	{
		$status_tenant='Tenant';
		$tanggal=get('tanggal');
		$x=0;

		$ls_sql	= "	SELECT  a.no_tagihan_listrik,b.nama_tenant,
							b.no_toko,b.jenis_usaha,b.periode_awal_sewa,
							b.periode_akhir_sewa,b.jangka_waktu,
							b.lokasi_tempat,b.status_tenant,c.luas_tempat,
							a.kwh_awal_meter,a.kwh_akhir_meter,a.kwh_terpakai,
							a.tarif_per_kwh,a.jumlah_pemakaian,a.mcb,
							a.biaya_beban,a.jumlah_biaya_beban,a.total_tagihan,
							a.tanggal
					FROM	pro_tagihan_listrik a
                   	INNER JOIN pro_tenant b ON a.no_toko = b.no_toko AND b.status_tenant = '$status_tenant'
         			INNER JOIN pro_sewa_gedung c ON a.no_toko = c.no_toko
					WHERE a.TANGGAL = '$tanggal' ";		

		$ls_sql2	= "	SELECT COUNT(1)
						FROM	pro_tagihan_listrik a
	                   	INNER JOIN pro_tenant b ON a.no_toko = b.no_toko AND b.status_tenant = '$status_tenant'
	         			INNER JOIN pro_sewa_gedung c ON a.no_toko = c.no_toko
						WHERE a.TANGGAL = '$tanggal'";
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('d-m-Y');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Tagihan Listrik_".$date);

		

			
		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$this->excel->getActiveSheet()->setCellValue('A4', 'No Tagihan Listrik');
			$this->excel->getActiveSheet()->mergeCells('A4:A5');
			$this->excel->getActiveSheet()->setCellValue('B4', 'Nama Tenant');
			$this->excel->getActiveSheet()->mergeCells('B4:B5');
			$this->excel->getActiveSheet()->setCellValue('C4', 'Toko');
			$this->excel->getActiveSheet()->setCellValue('C5', 'No.');
			$this->excel->getActiveSheet()->setCellValue('D4', 'Jenis Usaha');
			$this->excel->getActiveSheet()->mergeCells('D4:D5');
			$this->excel->getActiveSheet()->setCellValue('E4', 'Periode Awal Sewa');
			$this->excel->getActiveSheet()->mergeCells('E4:F5');
			$this->excel->getActiveSheet()->setCellValue('G4', 'Jangka Waktu');
			$this->excel->getActiveSheet()->mergeCells('G4:G5');
			$this->excel->getActiveSheet()->setCellValue('H4', 'Luas');
			$this->excel->getActiveSheet()->setCellValue('H5', ' M2');
			$this->excel->getActiveSheet()->getStyle('A4:H5')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);	
			$this->excel->getActiveSheet()->getStyle('A4:H5')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$this->excel->getActiveSheet()->setCellValue('I4', 'Perhitungan Pemakaian');
			$this->excel->getActiveSheet()->mergeCells('I4:J4');
			$this->excel->getActiveSheet()->getStyle('I4:J4')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$this->excel->getActiveSheet()->setCellValue('I5', 'Angka Awal (KWH)');
			$this->excel->getActiveSheet()->setCellValue('J5', 'Angka Akhir (KWH)');
			$this->excel->getActiveSheet()->setCellValue('K4', 'Jumlah Pemakaian (KWH)');
			$this->excel->getActiveSheet()->mergeCells('K4:K5');
			$this->excel->getActiveSheet()->setCellValue('L4', 'Tarif Per KWH');
			$this->excel->getActiveSheet()->setCellValue('L5', 'Per KWH');
			$this->excel->getActiveSheet()->setCellValue('M4', 'Total Pemakaian');
			$this->excel->getActiveSheet()->mergeCells('M4:M5');
			$this->excel->getActiveSheet()->getStyle('K4:M5')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$this->excel->getActiveSheet()->getStyle('K4:M5')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
			$this->excel->getActiveSheet()->setCellValue('N4', 'MCB yang terpakai');
			$this->excel->getActiveSheet()->mergeCells('N4:N5');
			$this->excel->getActiveSheet()->setCellValue('O4', 'Biaya');
			$this->excel->getActiveSheet()->setCellValue('O5', 'Beban');
			$this->excel->getActiveSheet()->setCellValue('P4', 'Total');
			$this->excel->getActiveSheet()->setCellValue('P5', 'Biaya Beban');
			$this->excel->getActiveSheet()->setCellValue('Q4', 'Grand Total');
			$this->excel->getActiveSheet()->mergeCells('Q4:Q5');
			$this->excel->getActiveSheet()->getStyle('N4:Q5')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$this->excel->getActiveSheet()->getStyle('N4:Q5')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

			
			$this->excel->getActiveSheet()->getStyle('A4:Q5')->applyFromArray($styleArrayBorder);
			$this->excel->getActiveSheet()->getStyle('A4:Q5')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'B2B2B2')));
			

			$x = 7;

			for($i=0;$i<=$data_p['total']-1;$i++){
				$x++;

				$rows = $data_p['rows'];
				$rows2 = $rows[$i];

				$this->excel->getActiveSheet()->setCellValue('A'.$x, $rows2['no_tagihan_listrik']);
				$this->excel->getActiveSheet()->setCellValue('B'.$x, $rows2['nama_tenant']);
				$this->excel->getActiveSheet()->setCellValue('C'.$x, $rows2['no_toko']);
				$this->excel->getActiveSheet()->setCellValue('D'.$x, $rows2['jenis_usaha']);
				$this->excel->getActiveSheet()->setCellValue('E'.$x, $rows2['periode_awal_sewa']);
				$this->excel->getActiveSheet()->setCellValue('F'.$x, $rows2['periode_akhir_sewa']);
				$this->excel->getActiveSheet()->setCellValue('G'.$x, $rows2['jangka_waktu']);
				$this->excel->getActiveSheet()->setCellValue('H'.$x, $rows2['luas_tempat']);
				$this->excel->getActiveSheet()->setCellValue('I'.$x, $rows2['kwh_awal_meter']);
				$this->excel->getActiveSheet()->setCellValue('J'.$x, $rows2['kwh_akhir_meter']);
				$this->excel->getActiveSheet()->setCellValue('K'.$x, $rows2['kwh_terpakai']);
				$this->excel->getActiveSheet()->setCellValue('L'.$x, $rows2['tarif_per_kwh']);
				$this->excel->getActiveSheet()->setCellValue('M'.$x, $rows2['jumlah_pemakaian']);
				$this->excel->getActiveSheet()->setCellValue('N'.$x, $rows2['mcb']);
				$this->excel->getActiveSheet()->setCellValue('O'.$x, $rows2['biaya_beban']);
				$this->excel->getActiveSheet()->setCellValue('P'.$x, $rows2['jumlah_biaya_beban']);
				$this->excel->getActiveSheet()->setCellValue('Q'.$x, $rows2['total_tagihan']);

				$this->excel->getActiveSheet()->getStyle('A'.$x.':Q'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

				$this->excel->getActiveSheet()->setCellValue('A1', strtoupper('Laporan Pemakaian Listrik / KWH Tenant '.$rows2['lokasi_tempat'].' periode '.$rows2['tanggal']));
				$this->excel->getActiveSheet()->setCellValue('A2', $rows2['tanggal']);	
			}
		}

			
			

		$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('A8:Q'.$x)->applyFromArray($styleArray);
		unset($styleArray);

		$styleArray1 = array(
		    'font'  => array(
		    'bold'  => true,
		    'uppercase' => true,
		    'size'  => 11,
		    'name'  => 'Calibri'
		    )
		);

		$this->excel->getActiveSheet()->getColumnDimension('A')->setWidth(17.3);
		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(23);	
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(9);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(30);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('J')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('K')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('L')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('M')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('N')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('O')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('P')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('Q')->setWidth(22);
		

	/*	$this->excel->getActiveSheet()->getStyle('D1:E'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('E1:E'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);*/

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		//$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Laporan Tagihan Listrik_'.$date.'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}


	

	

	function terbilang($x)
	{
	  $abil = array("", "satu", "dua", "tiga", "empat", "lima", "enam", "tujuh", "delapan", "sembilan", "sepuluh", "sebelas");
	  if ($x < 12)
	    return " " . $abil[$x];
	  elseif ($x < 20)
	    return $this->terbilang($x - 10) . " belas";
	  elseif ($x < 100)
	    return $this->terbilang($x / 10) . " puluh" . $this->terbilang($x % 10);
	  elseif ($x < 200)
	    return " seratus" . terbilang($x - 100);
	  elseif ($x < 1000)
	    return $this->terbilang($x / 100) . " ratus" . $this->terbilang($x % 100);
	  elseif ($x < 2000)
	    return " seribu" . terbilang($x - 1000);
	  elseif ($x < 1000000)
	    return $this->terbilang($x / 1000) . " ribu" . $this->terbilang($x % 1000);
	  elseif ($x < 1000000000)
	    return $this->terbilang($x / 1000000) . " juta" . $this->terbilang($x % 1000000);
	}


	

	function mitra_aktif()
	{
		
		$x=0;

		$ls_sql	= " SELECT	*
					FROM	pro_mitra
					WHERE	UPPER(status_mitra) = 'MITRA AKTIF' AND
							(UPPER(kode_mitra) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(ktp) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(situ) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(siup) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(npwp) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_mitra) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(alamat_lengkap) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_telp) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_hand) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(status_mitra) LIKE '%".strtoupper(post('keyword'))."%') 
							ORDER BY ".(post('sort')=='' ? 'kode_mitra' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
	
		$ls_sql2	= "	SELECT COUNT(1)
					FROM	pro_mitra
					WHERE	UPPER(status_mitra) = 'MITRA AKTIF' AND
							(UPPER(kode_mitra) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(ktp) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(situ) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(siup) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(npwp) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_mitra) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(alamat_lengkap) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_telp) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_hand) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(status_mitra) LIKE '%".strtoupper(post('keyword'))."%')
							ORDER BY ".(post('sort')=='' ? 'kode_mitra' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('Y-m-d');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Laporan Mitra");

		$no = 1;

			
		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$this->excel->getActiveSheet()->setCellValue('B8', 'NO');
			$this->excel->getActiveSheet()->setCellValue('C8', 'KODE MITRA');
			$this->excel->getActiveSheet()->setCellValue('D8', 'KTP');
			$this->excel->getActiveSheet()->setCellValue('E8', 'SITU');
			$this->excel->getActiveSheet()->setCellValue('F8', 'SIUP');
			$this->excel->getActiveSheet()->setCellValue('G8', 'NPWP');
			$this->excel->getActiveSheet()->setCellValue('H8', 'NAMA PEMILIK');
			$this->excel->getActiveSheet()->setCellValue('I8', 'ALAMAT LENGKAP');
			$this->excel->getActiveSheet()->setCellValue('K8', 'NO TELEPON');
			$this->excel->getActiveSheet()->setCellValue('K8', 'NO HANDPHONE');
			$this->excel->getActiveSheet()->setCellValue('L8', 'STATUS MITRA');
			
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'EEEE11')));
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$x = 8;

			for($i=0;$i<=$data_p['total']-1;$i++){
				$x++;

				$rows = $data_p['rows'];
				$rows2 = $rows[$i];

				$this->excel->getActiveSheet()->setCellValue('B'.$x, $no);
				$this->excel->getActiveSheet()->setCellValue('C'.$x, $rows2['kode_mitra']);
				$this->excel->getActiveSheet()->setCellValue('D'.$x, $rows2['ktp']);
				$this->excel->getActiveSheet()->setCellValue('E'.$x, $rows2['situ']);
				$this->excel->getActiveSheet()->setCellValue('F'.$x, $rows2['siup']);
				$this->excel->getActiveSheet()->setCellValue('G'.$x, $rows2['npwp']);
				$this->excel->getActiveSheet()->setCellValue('H'.$x, $rows2['nama_pemilik']);
				$this->excel->getActiveSheet()->setCellValue('I'.$x, $rows2['alamat_lengkap']);
				$this->excel->getActiveSheet()->setCellValue('J'.$x, $rows2['no_telp']);
				$this->excel->getActiveSheet()->setCellValue('K'.$x, $rows2['no_hand']);
				$this->excel->getActiveSheet()->setCellValue('L'.$x, $rows2['status_mitra']);
				$no++;
			}
		}

		$this->excel->getActiveSheet()->setCellValue('B4', strtoupper("Laporan Mitra"));
		$this->excel->getActiveSheet()->setCellValue('B5', '('.$date.')');			

		$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('B8:L'.$x)->applyFromArray($styleArray);
		unset($styleArray);

		$styleArray1 = array(
		    'font'  => array(
		    'bold'  => true,
		    'uppercase' => true,
		    'size'  => 11,
		    'name'  => 'Calibri'
		    )
		);

		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(15);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(15);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(15);
		$this->excel->getActiveSheet()->getColumnDimension('J')->setWidth(15);
		$this->excel->getActiveSheet()->getColumnDimension('K')->setWidth(15);
		$this->excel->getActiveSheet()->getColumnDimension('L')->setWidth(15);


		$this->excel->getActiveSheet()->getStyle('D1:L'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('L1:L'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Laporan Mitra Aktif_'.$date.'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}

	function laporan_perangkat()
	{
		
		$x=0;

		$ls_sql	= " SELECT	*
					FROM	pro_barang
					WHERE	(UPPER(kode_barang) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_barang) LIKE '%".strtoupper(post('keyword'))."%') 
							ORDER BY ".(post('sort')=='' ? 'kode_barang' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
	
		$ls_sql2	= "	SELECT COUNT(1)
					FROM	pro_barang
					WHERE	(UPPER(kode_barang) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_barang) LIKE '%".strtoupper(post('keyword'))."%') 
							ORDER BY ".(post('sort')=='' ? 'kode_barang' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('Y-m-d');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Laporan Perangkat_".$date);

		$no = 1;

			
		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$this->excel->getActiveSheet()->setCellValue('B8', 'NO');
			$this->excel->getActiveSheet()->setCellValue('C8', 'KODE BARANG');
			$this->excel->getActiveSheet()->setCellValue('D8', 'NAMA BARANG');
			$this->excel->getActiveSheet()->setCellValue('E8', 'NAMA MERK');
			$this->excel->getActiveSheet()->setCellValue('F8', 'SPESIFIKASI');
			$this->excel->getActiveSheet()->setCellValue('G8', 'KONDISI BARANG');
			$this->excel->getActiveSheet()->setCellValue('H8', 'TIPE');
			$this->excel->getActiveSheet()->setCellValue('I8', 'HARGA');
			$this->excel->getActiveSheet()->setCellValue('J8', 'JUMLAH');
			$this->excel->getActiveSheet()->setCellValue('K8', 'KETERANGAN');

			$this->excel->getActiveSheet()->getStyle('B8:K8')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('B8:K8')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'EEEE11')));
			$this->excel->getActiveSheet()->getStyle('B8:K8')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$x = 8;

			for($i=0;$i<=$data_p['total']-1;$i++){
				$x++;

				$rows = $data_p['rows'];
				$rows2 = $rows[$i];

				$this->excel->getActiveSheet()->setCellValue('B'.$x, $no);
				$this->excel->getActiveSheet()->setCellValue('C'.$x, $rows2['kode_barang']);
				$this->excel->getActiveSheet()->setCellValue('D'.$x, $rows2['nama_barang']);
				$this->excel->getActiveSheet()->setCellValue('E'.$x, $rows2['nama_merek']);
				$this->excel->getActiveSheet()->setCellValue('F'.$x, $rows2['spesifikasi']);
				$this->excel->getActiveSheet()->setCellValue('G'.$x, $rows2['kondisi']);
				$this->excel->getActiveSheet()->setCellValue('H'.$x, $rows2['tipe']);
				$this->excel->getActiveSheet()->setCellValue('I'.$x, $rows2['harga']);
				$this->excel->getActiveSheet()->setCellValue('J'.$x, $rows2['jumlah']);
				$this->excel->getActiveSheet()->setCellValue('K'.$x, $rows2['keterangan']);
			}
		}

		$this->excel->getActiveSheet()->setCellValue('B4', strtoupper("Laporan Komplain"));
		$this->excel->getActiveSheet()->setCellValue('B5', '('.$date.')');			

		$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('B8:H'.$x)->applyFromArray($styleArray);
		unset($styleArray);

		$styleArray1 = array(
		    'font'  => array(
		    'bold'  => true,
		    'uppercase' => true,
		    'size'  => 11,
		    'name'  => 'Calibri'
		    )
		);

		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(15);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('J')->setWidth(15);
		$this->excel->getActiveSheet()->getColumnDimension('K')->setWidth(22);

		//$this->excel->getActiveSheet()->getStyle('D1:H'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('K1:K'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Laporan Perangkat_'.$date.'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}

}
?>		